package com.weimob.mcloud.wechatwork.customer.enums;

/**
 * 逻辑错误定义
 * 统一制定业务错误
 *
 * @Author LeoLee
 * @Date 2022/8/22 20:43
 * @Version 1.0
 */
public enum ErrorCodeEnum {

    /**
     * 相关基础业务异常(1000000开始)
     */
    GET_PRIVATE_SPHERE_FAILED_NULL_CORPID(1000000L, "获取私域失败，corpId为空"),
    PRIVATE_SPHERE_IS_NULL(1000001L, "私域为空"),

    /**
     * 数据隔离相关异常(2000000开始)
     */
    DONT_OVERRIDED_PERMISSION_CHANGE_LOGIC(2000000L, "请重写权限变更的逻辑，默认实现不可用，强制重写")
    ;

    private Long code;

    private String errorDesc;

    ErrorCodeEnum(Long code, String errorDesc) {
        this.code = code;
        this.errorDesc = errorDesc;
    }

    public Long getCode() {
        return code;
    }

    public void setCode(Long code) {
        this.code = code;
    }

    public String getErrorDesc() {
        return errorDesc;
    }

    public void setErrorDesc(String errorDesc) {
        this.errorDesc = errorDesc;
    }

    public static ErrorCodeEnum getErrorCodeEnum(Long code) {
        if (null == code) {
            return null;
        }
        for (ErrorCodeEnum e : ErrorCodeEnum.values()) {
            if (e.getCode().longValue() == code.longValue()) {
                return e;
            }
        }
        return null;
    }

    public static String getErrorCodeEnumDesc(Long code) {
        ErrorCodeEnum errorCodeEnum = getErrorCodeEnum(code);
        if (errorCodeEnum == null) {
            return null;
        }
        return errorCodeEnum.getErrorDesc();
    }
}
